public class Solution1328 {
    public String breakPalindrome(String palindrome) {
        if (palindrome.length()==1){
            return "";
        }
        int p=0;
        while (p<palindrome.length() && palindrome.charAt(p)=='a'){
            p++;
        }
        if (p==palindrome.length()){
            StringBuilder stringBuilder=new StringBuilder(palindrome);
            stringBuilder.setCharAt(stringBuilder.length()-1,'b');
            return stringBuilder.toString();
        }
        if (palindrome.length()%2==1 && p==palindrome.length()/2){
            boolean flag=true;
            for (int i=p+1;i<palindrome.length();i++){
                if (palindrome.charAt(i)!='a'){
                    flag=false;
                }
            }
            if (!flag){
                return palindrome.substring(0,p).concat("a").concat(palindrome.substring(p+1));
            }else {
                return palindrome.substring(0,palindrome.length()-1).concat("b");
            }
        }else {
            return palindrome.substring(0,p).concat("a").concat(palindrome.substring(p+1));
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution1328().breakPalindrome("abccba"));
    }
}
